<?php 

class StorageFactory
{
  const FILE = 1;
  
  protected $list = array();
  /**
   * Singleton variable
   * 
   * @var Object
   */
  protected static $self;
  /**
   * Get singleton instance
   */
  public static function instance($config = array())
  {
    if(!is_object(self::$self))
    {
      self::$self = new StorageFactory($config); 
    }

    return self::$self;
  }
  /**
   * Class constructor
   * 
   * @param array $config
   */
  public function __construct($config)
  {
    $this->list[self::FILE] = array(
      "class"   => "Storage_File",
      "options" => array(),    
    );
  }
  /**
   * Method to get needed storage
   * @param unknown_type $type
   * @param unknown_type $options
   */
  public function get($type, $options)
  {
    if(!isset($this->list[$type]))
    {
      throw new Exception("Storage not found.");
    }
    
    $result   = $this->list[$type];
    $class    = $result["class"];
    $options  = array_merge($result["options"], $options);
    
    return new $class($options);
  }
}
